package com.wy.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wy.common.R;

import com.wy.service.IPetTypeService;
import com.wy.entity.PetType;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王昭贵
 * @since 2023-04-20
 */
@RestController
@RequestMapping("/pet-type")
public class PetTypeController {

    @Resource
    private IPetTypeService petTypeService;

    // 新增或者更新
    @PostMapping
    public R save(@RequestBody PetType petType) {
        petTypeService.saveOrUpdate(petType);
        return R.success("");
    }

    @DeleteMapping("/{id}")
    public R delete(@PathVariable Integer id) {
        petTypeService.removeById(id);
        return R.success("");
    }

    @GetMapping
    public R findAll() {
        return R.success(petTypeService.list());
    }

    @GetMapping("/{id}")
    public R findOne(@PathVariable Integer id) {
        return R.success(petTypeService.getById(id));
    }

    @GetMapping("/page")
    public R findPage(@RequestParam Integer page,
                                @RequestParam Integer pageSize) {
        QueryWrapper<PetType> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return R.success(petTypeService.page(new Page<>(page, pageSize), queryWrapper));
    }

    @GetMapping("/list")
    public R findPage() {
        List<PetType> list = petTypeService.list();
        return R.success(list);
    }

}

